ViewOperate = function(listView, operateConfig, operateDiv) {

	var instance = this;

	this.operateDiv = operateDiv;

	/***************************************************************************
	 * 列表视图对象
	 **************************************************************************/
	this.listView = listView;

	/***************************************************************************
	 * 操作配置
	 **************************************************************************/
	this.operateConfig = operateConfig;

	/*******************************************
	 * 操作按钮集合
	 ******************************************/
	this.operateButtons	=	new Array();
	
	/***************************************************************************
	 * 视图操作绘制
	 **************************************************************************/
	this.operateDraw = function() {

		if (undefined == instance.operateConfig) {
			return;
		}
		
		var length	=	instance.operateConfig.length;
		for ( var x = 0; x < length; x++) {
			var ope = instance.operateConfig[x];
			
			var link = $('<button class="btn btn-primary" >'+ope.name+'</button>');
//			var link = $("<a href='#' opeIndex="+x+"></a>");
			link.attr("opeIndex",x);
			link.bind("click", function() {
				instance.processOperate(this);
			});
			//link.text(ope.name);
			instance.operateButtons[x] = link;
			operateDiv.append(link);

			var icon = ope.icon;
			if (undefined == icon || "" == icon) {
				if ("dataAdd" == ope.type) {
					icon = "icon-add";
				} else if ("dataEdit" == ope.type) {
					icon = "icon-edit";
				} else if ("dataDelete" == ope.type) {
					icon = "icon-remove";
				} else if ("dataBatDelete" == ope.type) {
					icon = "icon-remove";
				} else if ("dataClear" == ope.type) {
					icon = "icon-remove";
				} else if ("forward" == ope.type) {
					icon = "icon-mini-add";
				} else if ("excelImport" == ope.type) {
					icon = "icon-redo";
				} else if ("excelExport" == ope.type) {
					icon = "icon-undo";
				}
			}
//			link.linkbutton({
//				plain : true,
//				iconCls : icon
//			});
			if (x != operateConfig.length - 1) {
				//operateDiv.append("&nbsp;&nbsp;|&nbsp;&nbsp;");
			}
		}
		instance.refreshOperates();
	};

	/**********************************************
	 * 视图操作处理
	 ***********************************************/
	this.processOperate = function(obj) {
		var level	=	parseInt($(obj).attr("opeIndex"));
		var operate = instance.operateConfig[level];
		var type = operate.type;
		var beforeCheck = instance.onBeforeAction(operate);
		if (false == beforeCheck) {
			return;
		}
		if ("dataAdd" == type) {
			listView.onAdd();
		} else if ("dataEdit" == type) {
			listView.onEdit();
		} else if ("dataDelete" == type) {
			listView.onDelete();
		} else if ("dataBatDelete" == type) {
			listView.onBatDelete();
		}
		instance.onAfterAction(operate);
	};
	
	/************************************************
	 * 视图操作刷新
	 ***********************************************/
	this.refreshOperates	=	function(){
		
		var row	=	listView.selectRow;
		for(var x=0;x<instance.operateButtons.length;x++){
			var config	=	instance.operateConfig[x];
			var readCheck	=	instance.actionReadonlyCheck(config);
			if(true == readCheck){
				//instance.operateButtons[x].linkbutton('disable');
			}else{
				//instance.operateButtons[x].linkbutton('enable');
			}
			
			var hideCheck	=	instance.actionHideCheck(config);
			if(true == hideCheck){
				//instance.operateButtons[x].hide();
			}
		}
	};
	
	/*************************************
	 * 操作执行前调用 
	 ************************************/
	this.onBeforeAction		=	function(config){
		if(undefined != config.beforeExecuteScript && "" != config.beforeExecuteScript){
			return ( new Function(  config.beforeExecuteScript ) )();
		}
		return true;
	}
	
	/*************************************
	 * 操作执行前调用 
	 ************************************/
	this.onAfterAction		=	function(config){
		if(undefined != config.afterExecuteScript && "" != config.afterExecuteScript){
			eval(config.afterExecuteScript );
		}
	}

	/**********************************
	 * 操作只读检测
	 * @param config
	 ***********************************/
	this.actionReadonlyCheck	=	function(config){
		if(undefined != config.onlyReadCondition && "" != config.onlyReadCondition){
			return ( new Function(  config.onlyReadCondition ) )();
		}else{
			if("dataEdit" == config.type || "dataDelete" == config.type){
				if(undefined == listView.getSelectedRow()){
					return true;
				}
			}else if("dataBatDelete" == config.type){
				var rows	=	listView.getSelectedRows();
				if(undefined == rows || rows.length == 0){
					return true;
				}
			}
		}
		return false;
	}
	/**********************************
	 * 操作隐藏检测
	 * @param config
	 ***********************************/
	this.actionHideCheck	=	function(config){
		if(undefined != config.hideCondition && "" != config.hideCondition){
			return ( new Function(  config.hideCondition ) )();
		}
		return false;
	}
}